-- DOCUMENTATION: Group Chat Channel Detection
-- --------------------------------------------
-- Basically, things like IsInRaid() returns true if you're in LFR.  Using
-- /raid in LFR automatically changes it to /instance if you type it.  However
-- LUA functions like SendChatMessage() using "RAID" as a chatTypeId will toss
-- you the error about not being in a raid group.
--
-- So to solve this, I used the above code, which tells you what KIND of group
-- you're in.  It differentiates between a 'random' group (BGs, LFR, LFD, or
-- Scenarios are this kind) or 'home' groups (Groups you form yourself are this
-- kind).  The 'random' groups require "INSTANCE_CHAT" be the chatTypeId; while
-- real groups you formed yourself are ok to use "PARTY" and "RAID" as
-- chatTypeIds.
--
-- So you can change some code around in Fatality to use the following
-- conditions:
--
-- If GetNumGroupMembers(LE_PARTY_CATEGORY_HOME) ~= 0  -- then you are in a
-- real group, formed by you manually.
--
-- If GetNumGroupMembers(LE_PARTY_CATEGORY_INSTANCE) ~= 0 -- then you are in
-- a random group created by LFR, LFD, Battlegrounds, or Scenarios.  In this
-- case, you would need to send chat to "INSTANCE_CHAT" with a command like
-- SendChatMessage("Text you want to say", "INSTANCE_CHAT");
--
-- Now you can be ~= 1 on BOTH of the above conditions.  This would happen if
-- you formed a group of pals, and then joined LFR/LFD/BG together.  In that
-- situation, using "PARTY" in a SendChatMessage would only be visible to the
-- players you were grouped with while in the queue.  It will not be visible
-- by the random players you got put together with, except possibly in LFD.
-- Post 5.1, probably not in LFD, but i've not tested this.
--
-- So obviously, if you have ~0 HOME, and =0 INSTANCE, you're not in
-- LFR/LFD/BG/Scen; so you'd want to send chat to RAID or PARTY.
--
-- If you have ~0 INSTANCE and =0 HOME, you would be in LFR/LFD/BG/Scenario
-- solo, so you would just send to INSTANCE_CHAT.
--
-- If you were =0 INSTANCE and =0 HOME, you're not in any group; so you can
-- just use print() to print stuff to yourself.
--
-- If you have ~0 INSTANCE and ~0 HOME, you're in both kinds of groups, and
-- could privately chat to your mates with PARTY, and with the other random
-- players in INSTANCE_CHAT.
--
-- END DOCUMENTATION --


-- LUA CODE: Group Chat Channel Detection --
if (enableChatMsg) then
	-- if: alone, no group
	if (GetNumGroupMembers(LE_PARTY_CATEGORY_HOME) == 0 and GetNumGroupMembers(LE_PARTY_CATEGORY_INSTANCE) == 0) then
		print(format("%s!", "MSG TO SELF"))
	-- else if: self-made group (not LFD, LFR, BG or Scenario)
	elseif (GetNumGroupMembers(LE_PARTY_CATEGORY_INSTANCE) == 0 and GetNumGroupMembers(LE_PARTY_CATEGORY_HOME) ~= 0) then
		SendChatMessage(format("%s!", "MSG TO PARTY"), "PARTY")
	-- else if: random instance group (LFR, LFD, BG, Scenario)
	elseif (GetNumGroupMembers(LE_PARTY_CATEGORY_HOME) == 0 and GetNumGroupMembers(LE_PARTY_CATEGORY_INSTANCE) ~= 0) then
		SendChatMessage(format("%s!", "MSG TO INSTANCE"), "INSTANCE_CHAT")
	end
end
-- END CODE: Group Chat Channel Detection --
